interface people{
    name?: string,
    age: number
}


// 返回值是一个对象， 对象{name, age}
function changePeople(newPeople:people):{name: string; age: number} {
    let returnPeople = {name:'white', age:18}
    if(newPeople.name){
       returnPeople.name =  newPeople.name
    }
    if(newPeople.age){
        returnPeople.age = newPeople.age
    }
    console.log(returnPeople)
    return returnPeople
}

changePeople({name: 'bob', age: 34})

interface animal{
   readonly name: string,
    color:string,
    // @ts-ignore
    age: number
}

function getAnimal(newAnimal: { color: string; name: string; age: number }):{ name: string; age: number; color: string }{
    let  animal1 = {name: 'cat', age: 2, color: 'red'}
    if(newAnimal.name){
        animal1.name = newAnimal.name
    }
     newAnimal.age = newAnimal.age ? newAnimal.age: 0
    console.log(animal1)
    return animal1
}

let animal2 = { name: 'mon',color: 'x', age:10}
getAnimal(animal2)

// interface animal{
//     x: number,
//     y: number
// }

// @ts-ignore
// let p1:animal = {x: 2,y: 10}
// console.log(p1)
